import sys
import os

#PYTHON_EGG_CACHE temporary files folder
os.environ['PYTHON_EGG_CACHE'] = '/tmp/'

#Adding the current project folder to the python path
#abspath = os.path.dirname(__file__)
#sys.path.append(abspath)
#os.chdir(abspath)

import web
from config import Config

#Declaring render templates
web.render = web.template.render(Config.templates, base='layout')
web.render_ajax = web.template.render(Config.templates)

#Connecting to database
web.db = web.database(host=Config.database['host'], dbn=Config.database['type'], user=Config.database['user'], pw=Config.database['password'], db=Config.database['db'])

urls = (
'/', 'Dashboard',
'/index', 'Dashboard',

'/groups/', 'groups.Groups',
'/groups/new', 'groups.New',
'/groups/update', 'groups.Update',
'/groups/delete/(.*)', 'groups.Delete',

'/hosts/', 'hosts.Hosts',
'/hosts/new/(.*)', 'hosts.New',
'/hosts/update', 'hosts.Update',
'/hosts/delete/(.*)', 'hosts.Delete',
'/hosts/broker/(.*)', 'hosts.Broker',

'/services/tunnel/(.*)', 'services.Tunnel',
)


class Dashboard:
    def GET(self):
        return web.render.dashboard(Config.version)

if __name__ == '__main__':
    application = web.application(urls, globals())
    application.run()
else:
    application = web.application(urls, globals()).wsgifunc()
